package com.sojson.project.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.sojson.project.dao.HotelRoomDao;
import com.sojson.project.entity.po.HotelRoom;
import com.sojson.project.entity.vo.HotelRoomVo;
import com.sojson.project.query.entity.bo.Select;
import com.sojson.project.service.HotelRoomService;
import com.sojson.util.StringUtil;
import com.sojson.util.file.constant.ConstantFileFieldName;
import com.sojson.util.file.depot.FileDepotUtil;
import com.sojson.util.file.enums.EFileTable;

/**
 * 房间信息Service实现类
 * 
 * @author liu
 * @date 2021-07-02
 */
@Service
public class HotelRoomServiceImpl implements HotelRoomService {

    @Resource
    private HotelRoomDao hotelRoomDaoImpl;

    /**
     * 单条插入
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int insert(HotelRoom hotelRoom) {
        int insert = hotelRoomDaoImpl.insert(hotelRoom);

        if (insert > 0) {
            FileDepotUtil.insertSync(EFileTable.HOTEL_ROOM, ConstantFileFieldName.IMG, hotelRoom.getImg());
            FileDepotUtil.insertListSync(EFileTable.HOTEL_ROOM, ConstantFileFieldName.IMGS, hotelRoom.getImgs());
        }
        return insert;
    }

    /**
     * 批量插入
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int insertList(HotelRoom hotelRoom) {
        int insertList = hotelRoomDaoImpl.insertList(hotelRoom.getHotelRooms());
        return insertList;
    }

    /**
     * 通过对象批量删除(物理删除)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int deleteByDto(HotelRoom hotelRoom) {
        int deleteByDto = hotelRoomDaoImpl.deleteByDto(hotelRoom);
        return deleteByDto;
    }

    /**
     * 统计全部数量
     * 
     * @return
     */
    @Override
    public int countAll() {
        int countAll = hotelRoomDaoImpl.countAll();
        return countAll;
    }

    /**
     * 查询所有
     * 
     * @return
     */
    @Override
    public List<HotelRoom> listAll() {
        List<HotelRoom> findAll = hotelRoomDaoImpl.listAll();
        return findAll;
    }

    /**
     * 根据对象统计数量
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int countByDto(HotelRoom hotelRoom) {
        int countByDto = hotelRoomDaoImpl.countByDto(hotelRoom);
        return countByDto;
    }

    /**
     * 根据对象查询
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public List<HotelRoom> listByDto(HotelRoom hotelRoom) {
        List<HotelRoom> findByDto = hotelRoomDaoImpl.listByDto(hotelRoom);
        return findByDto;
    }

    /**
     * 通过id删除(物理删除)
     * 
     * @param id
     * @return
     */
    @Override
    public int deleteById(Integer id) {
        int deleteById = hotelRoomDaoImpl.deleteById(id);
        return deleteById;
    }

    /**
     * 通过id数组删除(物理删除)
     * 
     * @param ids
     * @return
     */
    @Override
    public int deleteByIds(Integer[] ids) {
        int deleteByIds = hotelRoomDaoImpl.deleteByIds(ids);
        return deleteByIds;
    }

    /**
     * 通过id更新(全部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateAllById(HotelRoom hotelRoom) {
        int updateAllById = hotelRoomDaoImpl.updateAllById(hotelRoom);
        return updateAllById;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateAllByIdList(HotelRoom hotelRoom) {
        int updateAllByIdList = hotelRoomDaoImpl.updateAllByIdList(hotelRoom);
        return updateAllByIdList;
    }

    /**
     * 通过id列表更新(全部更新)(更新内容不相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateDtoListAllById(HotelRoom hotelRoom) {
        int updateDtoListAllById = hotelRoomDaoImpl.updateDtoListAllById(hotelRoom.getHotelRooms());
        return updateDtoListAllById;
    }

    /**
     * 通过id更新(局部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateById(HotelRoom hotelRoom) {
        HotelRoom findById = hotelRoomDaoImpl.findById(hotelRoom.getId());

        int updateById = hotelRoomDaoImpl.updateById(hotelRoom);

        if (updateById > 0) {
            FileDepotUtil.updateSync(EFileTable.HOTEL_ROOM.getCode(), ConstantFileFieldName.IMG, hotelRoom.getImg(),
                findById.getImg());
            FileDepotUtil.updateSync(EFileTable.HOTEL_ROOM.getCode(), ConstantFileFieldName.IMGS, hotelRoom.getImgs(),
                findById.getImgs());
        }
        return updateById;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateByIdList(HotelRoom hotelRoom) {
        int updateByIdList = hotelRoomDaoImpl.updateByIdList(hotelRoom);
        return updateByIdList;
    }

    /**
     * 通过id列表更新(局部更新)(更新内容不相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateDtoListById(HotelRoom hotelRoom) {
        int updateDtoListById = hotelRoomDaoImpl.updateDtoListById(hotelRoom.getHotelRooms());
        return updateDtoListById;
    }

    /**
     * 通过id查询
     * 
     * @param id
     * @return
     */
    @Override
    public HotelRoom findById(String id) {
        HotelRoom findById = hotelRoomDaoImpl.findById(id);
        return findById;
    }

    /**
     * 通过id数组查询
     * 
     * @param ids
     * @return
     */
    @Override
    public List<HotelRoom> findByIds(Integer[] ids) {
        List<HotelRoom> findByIds = hotelRoomDaoImpl.findByIds(ids);
        return findByIds;
    }

    /**
     * 通过对象查询id列表
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public List<Integer> findIdByDto(HotelRoom hotelRoom) {
        List<Integer> findIdByDto = hotelRoomDaoImpl.findIdByDto(hotelRoom);
        return findIdByDto;
    }

    /**
     * 通过no删除(物理删除)
     * 
     * @param no
     * @return
     */
    @Override
    public int deleteByNo(String no) {
        HotelRoom findByNo = hotelRoomDaoImpl.findByNo(no);

        int deleteByNo = hotelRoomDaoImpl.deleteByNo(no);

        if (deleteByNo > 0) {
            FileDepotUtil.deleteSync(findByNo.getImg());
            FileDepotUtil.deleteListSync(findByNo.getImgs());
        }
        return deleteByNo;
    }

    /**
     * 通过no数组删除(物理删除)
     * 
     * @param nos
     * @return
     */
    @Override
    public int deleteByNos(String[] nos) {
        int deleteByNos = hotelRoomDaoImpl.deleteByNos(nos);
        return deleteByNos;
    }

    /**
     * 通过no更新(全部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateAllByNo(HotelRoom hotelRoom) {
        int updateAllByNo = hotelRoomDaoImpl.updateAllByNo(hotelRoom);
        return updateAllByNo;
    }

    /**
     * 通过no列表更新(全部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateAllByNoList(HotelRoom hotelRoom) {
        int updateAllByNoList = hotelRoomDaoImpl.updateAllByNoList(hotelRoom);
        return updateAllByNoList;
    }

    /**
     * 通过no列表更新(全部更新)(更新内容不相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateDtoListAllByNo(HotelRoom hotelRoom) {
        int updateDtoListAllByNo = hotelRoomDaoImpl.updateDtoListAllByNo(hotelRoom.getHotelRooms());
        return updateDtoListAllByNo;
    }

    /**
     * 通过no更新(局部更新)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateByNo(HotelRoom hotelRoom) {
        int updateByNo = hotelRoomDaoImpl.updateByNo(hotelRoom);
        return updateByNo;
    }

    /**
     * 通过no列表更新(局部更新)(更新内容相同)
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public int updateByNoList(HotelRoom hotelRoom) {
        int updateByNoList = hotelRoomDaoImpl.updateByNoList(hotelRoom);
        return updateByNoList;
    }

    /**
     * 通过no列表更新(局部更新)(更新内容不相同)
     * 
     * @param hotelRooms
     * @return
     */
    @Override
    public int updateDtoListByNo(HotelRoom hotelRoom) {
        int updateDtoListByNo = hotelRoomDaoImpl.updateDtoListByNo(hotelRoom.getHotelRooms());
        return updateDtoListByNo;
    }

    /**
     * 通过no查询
     * 
     * @param no
     * @return
     */
    @Override
    public HotelRoom findByNo(String no) {
        HotelRoom findByNo = hotelRoomDaoImpl.findByNo(no);
        return findByNo;
    }

    /**
     * 通过no数组查询
     * 
     * @param nos
     * @return
     */
    @Override
    public List<HotelRoom> findByNos(String[] nos) {
        List<HotelRoom> findByNos = hotelRoomDaoImpl.findByNos(nos);
        return findByNos;
    }

    /**
     * 通过对象查询no列表
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public List<String> findNoByDto(HotelRoom hotelRoom) {
        List<String> findNoByDto = hotelRoomDaoImpl.findNoByDto(hotelRoom);
        return findNoByDto;
    }

    /**
     * 清空数据(物理清空)
     */
    @Override
    public int clear() {
        return hotelRoomDaoImpl.clear();
    }

    /**
     * 根据对象查询
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public List<HotelRoomVo> list(HotelRoomVo hotelRoom) {
        if (StringUtil.isBlankObjectListOne(hotelRoom.getStartTime(), hotelRoom.getEndTime())) {
            hotelRoom.setStartTime(null);
            hotelRoom.setEndTime(null);
        }
        return hotelRoomDaoImpl.list(hotelRoom);
    }

    /**
     * 通过no查询
     * 
     * @param no
     * @return
     */
    @Override
    public HotelRoomVo getInfo(String no) {
        return hotelRoomDaoImpl.getInfo(no);
    }

    /**
     * 获取下拉列表
     * 
     * @param hotelRoom
     * @return
     */
    @Override
    public List<Select> select(HotelRoomVo hotelRoom) {
        return hotelRoomDaoImpl.select(hotelRoom);
    }

}